//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.comprosoft.telnet.configuration;

import com.comprosoft.telnet.server.TelnetServer;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.CodeSource;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public enum ServerProperties {
    PORT_NUMBER("port.num", "23"),
    MAX_THREADS("max.threads", "120"),
    LOGIN_USERNAME("login.username", "administrator"),
    LOGIN_PASSWORD("login.password", "ecan"),
    JAR_PATH("env.jarpath", getJarPath());

    private final String propertyName;
    private final String defaultValue;
    private static final Logger logger = Logger.getLogger(ServerProperties.class.getName());
    private static final Properties properties = loadProperties();

    private ServerProperties(String name, String defaultValue) {
        this.propertyName = name;
        this.defaultValue = defaultValue;
    }

    public String getValue() {
        return properties != null && properties.getProperty(this.propertyName) != null ? properties.getProperty(this.propertyName) : this.defaultValue;
    }

    public String getDefaultValue() {
        return this.defaultValue;
    }

    private static String getJarPath() {
        String jarPath = null;

        try {
            CodeSource codeSource = TelnetServer.class.getProtectionDomain().getCodeSource();
            String jarDir = (new File(codeSource.getLocation().toURI().getPath())).getParentFile().getPath();
            String path = jarDir + File.separator + "server.properties";
            jarPath = jarDir + File.separator;
        } catch (Exception var4) {
            jarPath = "";
        }

        return jarPath;
    }

    private static Properties loadProperties() {
        Properties prop = new Properties();
        String jarPath = null;

        try {
            CodeSource codeSource = TelnetServer.class.getProtectionDomain().getCodeSource();
            String jarDir = (new File(codeSource.getLocation().toURI().getPath())).getParentFile().getPath();
            String path = jarDir + File.separator + "server.properties";
            jarPath = jarDir + File.separator;
            logger.log(Level.INFO, "Reading configuration file from [" + path + "]");
            InputStream in = new FileInputStream(path);
            if (in != null) {
                prop.load(in);
            }

            in.close();
        } catch (Exception var6) {
            var6.printStackTrace();
            logger.log(Level.WARNING, "Error reading configuration file. Default values will be used instead.");
        }

        return prop;
    }
}
